package example.service;

import example.mapper.RoleMapper;
import example.pojo.SysRole;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("roleService")
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    @Override
    public int add(SysRole role) {
        int count = 0;
        try {
            count = roleMapper.add(role);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }

    @Override
    public int upd(SysRole role) {
        int count = 0;
        try {
            count = roleMapper.upd(role);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }

    @Override
    public int del(Integer id) {
        int count = 0;
        try {
            count = roleMapper.del(id);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }

    @Override
    public List<SysRole> roleList() {
        List<SysRole> roleList = new ArrayList<>();
        try {
            roleList = roleMapper.roleList();
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
        return roleList;
    }

    @Override
    public SysRole selectRoleByRid(Integer id) {
        SysRole role = null;
        try {
            role = roleMapper.selectRoleByRid(id == null ? null : id);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
        return role;
    }

    @Override
    public int codeExist(String code) {
        int count = 0;
        try {
            count = roleMapper.codeExist(code);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }
}
